using AhpilyServer;
using AhpilyServers;
using GameServer.Logic;
using Protocol.Code;

namespace GameServer
{
    class NetMsgCenter : IApplication
    {
        IHeadler account = new AccountHeadler();
        IHeadler user = new UserHandler();
        MatchHandler match = new MatchHandler();
        MatchHandler2 match2 = new MatchHandler2();
        IHeadler chat = new ChatHandler();
        FightHandler fight = new FightHandler();
        FightHandler2 fight2 = new FightHandler2();

        public NetMsgCenter()
        {
            match.startFight += fight.StartFight;
            match2.startFight2 += fight2.StartFight;
        }
        public void OnConnect(ClientPeer client)
        {

        }

        public void OnDisconnect(ClientPeer client)
        {
            fight.OnDisconnect(client);
            fight2.OnDisconnect(client);
            match.OnDisconnect(client);
            match2.OnDisconnect(client);
            user.OnDisconnect(client);
            account.OnDisconnect(client);
            chat.OnDisconnect(client);
        }

        public void OnReceive(ClientPeer client, SocketMsg msg)
        {
           
            // 第一层解码
            switch (msg.OpCode)
            {
                case OpCode.ACCOUNT:
                    account.OnReceive(client, msg.SubCode, msg.Value);
                    break;
                case OpCode.USER:
                    user.OnReceive(client, msg.SubCode, msg.Value);
                    break;
                case OpCode.MATCH:
                    match.OnReceive(client, msg.SubCode, msg.Value);
                    break;
                case OpCode.MATCH2:
                    match2.OnReceive(client, msg.SubCode, msg.Value);
                    break;
                case OpCode.CHAT:
                    chat.OnReceive(client, msg.SubCode, msg.Value);
                    break;
                case OpCode.FIGHT:
                    fight.OnReceive(client, msg.SubCode, msg.Value);
                    break;
                default:
                    break;
            }
            
        }

    }
}
